home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Documentation / Books / Learn Java on the Macintosh / Learn Java Projects / 09.02 - employee 2 / Employee2.java < prev    next >
Text File  |  1996-04-22  |  2KB  |  64 lines

  1. /* -------------------------------------------------------------
  2. This applet illustrates working with instance variables
  3. and instance methods in different objects.
  4.  
  5. Java's classes: Applet    (applet)
  6.                 System    (lang)
  7.  
  8. Custom classes: Employee2
  9.                 Employee
  10.  
  11. ------------------------------------------------------------- */
  12. public class Employee2 extends java.applet.Applet {
  13.  
  14.    Employee e1;
  15.    Employee e2;
  16.    Employee e3;
  17.  
  18.    public void init() {
  19.       e1 = new Employee();
  20.       e1.hourlyWage = 10;
  21.       e1.hoursWorked = 20;
  22.       
  23.       e2 = new Employee();
  24.       e2.hourlyWage = 18;
  25.       e2.hoursWorked = 38;
  26.       
  27.       e3 = new Employee();
  28.       e3.hourlyWage = 12;
  29.       e3.hoursWorked = 52;
  30.    }
  31.    
  32.    public void start() {
  33.       System.out.println("");
  34.       System.out.println("Employee 1:");
  35.       e1.displayInfo();      
  36.       
  37.       System.out.println("");
  38.       System.out.println("Employee 2:");
  39.       e2.displayInfo();      
  40.       
  41.       System.out.println("");
  42.       System.out.println("Employee 3:");
  43.       e3.displayInfo();      
  44.    }
  45. }
  46.  
  47. class Employee {
  48.    int hourlyWage;
  49.    int hoursWorked;
  50.    
  51.    int earnedIncome() {
  52.       return hourlyWage * hoursWorked;
  53.    }
  54.    
  55.    void displayInfo() {
  56.       int earnedIncome;
  57.       
  58.       System.out.println("hourly wage = " + hourlyWage);
  59.       System.out.println("hours worked = " + hoursWorked);
  60.       
  61.       earnedIncome = earnedIncome();
  62.       System.out.println("earned income = " + earnedIncome);
  63.    }
  64. }